# -*- coding: utf-8 -*-
__author__ = 'lztkdr'
__date__ = '2020/4/13 9:17'

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Pycharm输出窗口有省略号，数据显示不全解决方法
pd.set_option('display.max_rows', 10)
pd.set_option('display.max_columns', 200)
pd.set_option('display.width', 1000)

# 如果要显示中文标题和坐标表示，需要添加以下两行代码
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

print('pd.__version__:', pd.__version__)

print('============================================================================================================')
"""
	统计出911数据中不同月份不同类型的电话的次数的变化情况
"""
df = pd.read_csv("./911.csv")
df["timeStamp"] = pd.to_datetime(df["timeStamp"])
df.set_index("timeStamp", inplace=True)
print(df.head())
print('================================================')
srs = df.title.str.split(':', expand=True)[0]
print(srs)
print(srs.unique())
print('================================================')
print([j.strftime('%Y%m%d') for j in srs.resample('M').groups])
print('================================================')

plt.figure(figsize=(20, 8), dpi=80)

x = [j.strftime('%Y%m%d') for j in srs.resample('M').groups]

for cate in srs.unique():
	count_list = []
	for ts, ser in srs.resample('M'):
		cnt = ser[ser == cate].count()
		count_list.append(cnt)
	plt.plot(x, count_list, label=cate)

plt.xticks(x, rotation=45)
plt.xlabel('月份')
plt.ylabel('电话次数')

plt.show()
